package org.megha.blog.example.selenium.yahoo;

import com.thoughtworks.selenium.Selenium;

public class HomePage implements Page {

	private static final String LOCATION = "http://www.yahoo.com/";
	private static final String SEARCH_INPUT_BOX = "name=p";
	private static final String SEARCH_SUBMIT_BOX = "id=search-submit";
	private static final String TIMEOUT = "30000";
	private final Selenium selenium;

	public HomePage(Selenium selenium) {
		this.selenium = selenium;
	}
	
	public void open() {
		selenium.open(LOCATION);
		selenium.waitForPageToLoad(TIMEOUT);
	}
	
	public SearchResultsPage searchFor(String keywords) {
		selenium.type(SEARCH_INPUT_BOX, keywords);
		selenium.click(SEARCH_SUBMIT_BOX);
		selenium.waitForPageToLoad(TIMEOUT);
		return new SearchResultsPage(selenium);
	}
	
	@Override
	public boolean isOnThisPage() {
		return LOCATION.equals(selenium.getLocation());
	}
}
